import { _decorator, Component, Node } from 'cc';
import { ICommandLifecycle } from './ICommandLifecycle';
import { BaseGuideCommand } from './BaseGuideCommand';
const { ccclass, property } = _decorator;

@ccclass('GuideCommandExecutor')
export class GuideCommandExecutor {

    private commands: BaseGuideCommand[] = [];
    private isRunning = false;

    constructor() {
        this.commands = [];
    }

    public add(command: BaseGuideCommand) {
        this.commands.push(command);
        if (!this.isRunning)
            this.run();
    }

    public async run() {
        this.isRunning = true;
        while (this.commands.length > 0) {
            try {
                await this.commands[0].execute();
                this.commands.shift();
            } catch (error) {
                console.error("命令执行失败:", error);
                break;
            }
        }

        this.isRunning = false;
    }
}


